﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AMS.Core.DataAccess;
using AMS.Core.Entities;

namespace AMS.Core.Manager
{
    public class CoreManager
    {
        private CoreDataAccess m_Access;

        public CoreManager()
        {
            m_Access = new CoreDataAccess();
        }

        public AssetInfo GetAssetInfo(string id)
        {
            AssetInfo ai=null;
            try
            {
                object obj = m_Access.GetSingleObjectById(typeof (AssetInfo).Name, id);
                if (obj != null && obj is AssetInfo)
                    ai = obj as AssetInfo;
                
            }
            finally
            {
                m_Access.CloseSession();
            }
            return ai;
        }

        public AssetInfo GetAssetInfoByWoCommandId(string woCommId)
        {
            AssetInfo ai = null;
            try
            {
                string hql = "Select o.AssetInfo From WoCommand o Where o.Id='"+woCommId+"'";
                IList lstObjs = m_Access.Session.CreateQuery(hql).List();
                if(lstObjs!=null && lstObjs.Count>0)
                {
                   ai = lstObjs[0] as AssetInfo;
                }
            }
            finally
            {
                m_Access.CloseSession();
            }
            return ai;
        }



        public AssetInfo GetAssetInfoByAssetId(string assetId)
        {
            AssetInfo ai = null;
            try
            {
                string hql = " From AssetInfo o Where o.Id='" + assetId + "'";
                IList lstObjs = m_Access.Session.CreateQuery(hql).List();
                if (lstObjs != null && lstObjs.Count > 0)
                {
                    ai = lstObjs[0] as AssetInfo;
                }
            }
            finally
            {
                m_Access.CloseSession();
            }
            return ai;
        }
    }
}
